package com.itheima.controller;

import com.itheima.exception.BusineseExcepiton;
import com.itheima.exception.SystemException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionAdviceHandler {
    @ExceptionHandler(BusineseExcepiton.class)
    public Result business(BusineseExcepiton e) {
        System.out.println(e.getMessage());
        String msg = "请过段时间再来试一下~";
        //        contains 字符串包含
        if (e.getMessage().contains("Data too long for column")) {
            msg = "你输入的类型太长了";
        }
        return new Result(Code.SYSTEM_ERR, null, msg);
    }

    @ExceptionHandler(SystemException.class)
    public Result systniss(SystemException e) {
        System.out.println("sadsad");
        return new Result(50030, null, "请重试");
    }

    @ExceptionHandler(Exception.class)
    public Result exception(Exception e) {
        System.out.println(e.getMessage());
        return new Result(50010, null, "请重试");
    }
}
